package com.demo.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import com.module.commonui.R;
import com.tg.appcommon.android.ResourcesUtil;


public class SettingItemTextViewEx extends SettingItemTextView {
    private String mMark;
    private ImageView leftBtn;
    private boolean leftBtnShow;
    private int mMarkTextColor;
    private int mMarkTextSize = 10;
    private TextView mMarkView;
    public SettingItemTextViewEx(Context context) {
        super(context);
        initContentView();
    }

    public SettingItemTextViewEx(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SettingItemTextViewEx(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initParam(context, attrs);
        initContentView();
    }

    @Override
    public int getLayoutResID() {
        return R.layout.settings_item_text_ex;
    }

    private void initParam(Context context, @Nullable AttributeSet attrs) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SettingItemTextViewEx);
        mMark = typedArray.getString(R.styleable.SettingItemTextViewEx_text_mark);
        leftBtnShow = typedArray.getBoolean(R.styleable.SettingItemTextViewEx_left_icon_visibility,false);
        mMarkTextColor = typedArray.getColor(R.styleable.SettingItemTextViewEx_ex_text_mark_color, context.getResources().getColor(R.color.global_customize_fixed_color_black));
        mMarkTextSize = typedArray.getInt(R.styleable.SettingItemTextViewEx_ex_text_mark_size, mMarkTextSize);
        typedArray.recycle();
    }

    public ImageView getLeftBtn(){
        return leftBtn;
    }

    private void initContentView() {
        mMarkView = mView.findViewById(R.id.tv_item_text_mark);
        mMarkView.setText(mMark);
        mMarkView.setTextColor(mMarkTextColor);
        mMarkView.setTextSize(mMarkTextSize);
        leftBtn = mView.findViewById(R.id.rl_text_bkg_left_arrow);
        if (leftBtn != null){
            leftBtn.setVisibility(leftBtnShow?VISIBLE:GONE);
        }
    }

    public void setMark(String mark){
        if (mMarkView != null) {
            mMarkView.setText(mark);
        }
    }

    public void setMarkColor(@ColorInt int color){
        if (mMarkView != null) {
            mMarkView.setTextColor(color);
        }
    }

    public void showMarkView(boolean show){
        if (mMarkView != null){
            mMarkView.setVisibility(show? VISIBLE : GONE);
        }
    }
    public void setMark(@StringRes int resId){
        String mark = ResourcesUtil.getString(resId);
        setMark(mark);
    }
}
